import dynamicKey from '@/components/SignUp/model/dynamicKey';
import Title from '@/components/Title';
import levelTitle from '@/views/legal/process/components/formMake/components/Title';
import { isJournalPlatform } from '@/views/resource/create/resourceData';

import { mapState } from 'vuex';
export default {
  components: {
    dynamicKey,
    Title,
    levelTitle
  },
  props: {
    ruleParentKey: {
      type: Array,
      default: () => []
    },
    dialog: {
      type: Boolean,
      default: false
    },
    labelWidth: {
      type: String,
      default: '100px'
    }
  },
  data() {
    return {
    };
  },
  computed: {
    formData: {
      get() {
        return this.modelData;
      },
      set() {
        this.$emit('changeValue');
      }
    },
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    }),
    isCommon() {
      const arr = ['小红书', '抖音', '微博', 'B站'];
      return !arr.includes(this.modelData.platformTypeName);
    },
    isJournalPlatform() {
      return isJournalPlatform(this.modelData.platformTypeName);
    },
    isRedBook() {
      return this.modelData.platformTypeName === '小红书';
    },
    isWeiBo() {
      return this.modelData.platformTypeName === '微博';
    },
    isDouYin() {
      return this.modelData.platformTypeName === '抖音';
    },
    kuaiShou() {
      return this.modelData.platformTypeName === '快手';
    },
    formRules() {
      if (!this.ruleParentKey) return {};
      let obj = {};
      this.ruleParentKey.forEach(key => {
        const requiredModel = this.modelData[key] ? this.modelData[key].requiredModel : {};
        obj = {
          ...obj,
          ...requiredModel
        };
      });
      return obj;
    }
  },
  methods: {
    validateForm(validate = true) {
      return new Promise((resolve, reject) => {
        if (validate) {
          this.$refs.formRef.validate(valid => {
            if (valid) {
              resolve(valid);
            } else {
              reject(false);
            }
          });
        } else {
          resolve(true);
        }
      });
    }
  }
};
